﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using LayerEntity.Producto;

namespace System2012.Listados
{
    public partial class frmListadoUnimedLP : DevExpress.XtraEditors.XtraForm
    {
        public ArrayList data;
        DataTable dtbUnd;
        int indexRow;

        public string Id_Producto { get; set; }
        public frmListadoUnimedLP()
        {
            this.InitializeComponent();
            MessageBox.Show(this.Id_Producto);
            if (!this.BGWListPrecios.IsBusy)
            {
                this.BGWListPrecios.RunWorkerAsync();
            }
        }

        public frmListadoUnimedLP(ArrayList Data)
        {
            this.InitializeComponent();
            this.Id_Producto = Data[0].ToString();
            if (!this.BGWListPrecios.IsBusy)
            {
                this.BGWListPrecios.RunWorkerAsync();
            }
        }

        private void BGWListPrecios_DoWork(object sender, DoWorkEventArgs e)
        {
            EPrecios objPre = new EPrecios();
            objPre.Condicion = string.Format("where id_producto='{0}'", this.Id_Producto);
            e.Result = System2012.SystemUtils.RecodManajerproducto.GetListaGeneralPrecios(objPre);
        }

        private void BGWListPrecios_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.dtbUnd = (DataTable)e.Result;
            this.gridControl1.DataSource = e.Result;
        }

        private void Seleccionar()
        {
            this.data = new ArrayList();
            this.data.Add(this.dtbUnd.Rows[this.indexRow]["id_unidad"]);//0
            this.data.Add(this.dtbUnd.Rows[this.indexRow]["id_lista"]);//1
            this.data.Add(this.dtbUnd.Rows[this.indexRow]["id_precios"]);//2
            this.data.Add(this.dtbUnd.Rows[this.indexRow]["unidad"]);//3
            this.Close();
        }

        private void frmListadoUnimedLP_Load(object sender, EventArgs e)
        {
        }

        private void gridView3_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            this.indexRow = e.FocusedRowHandle;
        }

        private void gridControl1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                this.Seleccionar();
            }
        }

        private void gridControl1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Seleccionar();
        }

        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.data = new ArrayList();
            this.Close();
        }
    }
}